package com.wwh.databasetest

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

class MemoDatabaseHelper(private val context : Context, name : String, version : Int) : SQLiteOpenHelper(context, name, null, version) {

    private val createMemo = "create table memo (" +
            "id integer primary key autoincrement," +
            "title text," +
            "content text)"

    override fun onCreate(db: SQLiteDatabase?) {
        db?.execSQL(createMemo)
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        if(oldVersion <= 2) {
            db?.execSQL("alter table memo add column `datetime` datetime")
        }
    }
}